from bokeh.embed import components
from bokeh.resources import INLINE
from flask import Flask, render_template
from huitu import zuigao, zuidi,  hangyexinzi, read_data, biao, shuliang, fenbu, chengshishuliang, xizi, \
    gongsi_leixing,xuelipinjun, xuelifenlei, hangyeciyun, hangyeshuliang, hangyezhanbi



app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/biaoge')
def biaoge():
    df =biao()
    new_df = df.head(20).to_html()
    return render_template('biaoge.html', the_data=new_df)

data=biao()

@app.route('/cities_shuliang', methods=["GET", "POST"])
def cities_shuliang():
    tu1=shuliang()
    tu2=fenbu()
    tu3=chengshishuliang()

    return render_template('chengshi_shuliang.html',
                           the_data=tu1,
                           the_res=tu2,
                           the_fenbu=tu3)


@app.route('/cities_xinzi')
def cities_xinzi():
    gao = zuigao()
    di = zuidi()
    tu=xizi()

    js_resources = INLINE.render_js()
    css_resources = INLINE.render_css()
    script1, div1 = components(gao)
    script2, div2 = components(di)

    return render_template('pingjunxinzi.html',
                           the_data=tu,
                           the_zuigao=gao,
                           the_zuidi=di,
                           plot_script=script1,
                           plot_div=div1,
                           plot_script2=script2,
                           plot_div2=div2,
                           js_resources=js_resources,
                           css_resources=css_resources
                           )


@app.route('/gongsi_xueli')
def gongsi_xueli():
    tu1=gongsi_leixing()
    tu2=xuelipinjun()
    tu3=xuelifenlei()

    return render_template('gongsixueli.html',
                           the_data=tu2,
                           the_leixing=tu1,
                           the_xueli=tu3
                           )


@app.route('/hangye_guimo')
def hangye_guimo():
    tu1=hangyeciyun()
    tu2=hangyeshuliang()
    tu3=hangyezhanbi()

    return render_template('hangyeguimo.html',
                               the_data=tu1,
                               the_guimo=tu2,
                               the_zhanbi=tu3
                               )


@app.route('/hangye_xinzi')
def hangye_xinzi():
    hangyedata = hangyexinzi()
    js_resources = INLINE.render_js()
    css_resources = INLINE.render_css()
    script, div = components(hangyedata)
    return render_template('hangyexinzi.html',
                           the_data=hangyedata,
                           plot_script=script,
                           plot_div=div,
                           js_resources=js_resources,
                           css_resources=css_resources
                           )


@app.route('/zongjie')
def zongjie():
    return render_template('shujuzongjie.html')


if __name__ == '__main__':
    app.run()
